import React, {useCallback, useState} from 'react';
import Child from './components/Child'

function App(props) {
    const [num,setNum] = useState(1)
    const [userName,setUserName] = useState('zhangsan')
    const [age,serAge] = useState(18)
    const changeUserName = useCallback(function (name) {
        console.log('111')
        setUserName(name)
    },[userName])
    const changeAge = useCallback(function () {
        console.log('222')
        if(age<22){
            serAge(age+1)
        }
    },[])
    return (
        <div>
            <button onClick={setNum.bind(null,num+1)}>{num}</button>
            <button onClick={changeUserName.bind(null,'lisi')}>{userName}</button>
            <button onClick={changeAge.bind(null)}>{age}</button>
            <Child userName={userName} age={age} changeUserName={changeUserName}/>
        </div>
    );
}

export default App;